package C;

import java.util.*;
import java.util.stream.Collectors;

public class C53 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[] nums = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int k = Integer.parseInt(sc.nextLine());
        getResult(nums,k);
    }
    public static void getResult(int[] nums,int k) {
        Map<Integer,Integer> map = new HashMap<>();
        for (int num : nums) {
                    map.put(num,map.getOrDefault(num,0)+1);
        }
        map = map.entrySet().stream()
                .filter(entry->entry.getValue()>=k)
                .collect(Collectors.toMap(Map.Entry::getKey,Map.Entry::getValue));
        System.out.println("map: "+map);
        if (map.isEmpty()) {
            System.out.println(0);
            return;
        }
        ArrayList<Map.Entry<Integer,Integer>> list = new ArrayList<>(map.entrySet());
        list.sort((a,b)->{
            return b.getValue()!=a.getValue() ? (b.getValue()-a.getValue()) : (a.getKey()-b.getKey());
        });
        System.out.println(list.size());
        list.forEach(a-> System.out.println(a.getKey()));
    }
}
